{js:artTemplate}
<script type='text/javascript' src='{theme:javascript/artTemplate/area_select.js}'></script>
<script type='text/javascript' src='{theme:javascript/orderFormClass.js}'></script>
<style>
.block-row {
border: none;
}
</style>
<script type='text/javascript'>
//创建订单表单实例
orderFormInstance = new orderFormClass();

//DOM加载完毕
jQuery(function(){
	//使用红包按钮
	$('#ticket_a').click(function()
	{
		//第一次打开时生成缓存数据
		if($.trim($('#ticket_show_box').text()) == '')
		{
			var ticketList = {echo:JSON::encode($this->prop)};
			for(var index in ticketList)
			{
				var ticketHtml = template.render('ticketTrTemplate',{item:ticketList[index]});
				$('#ticket_show_box').append(ticketHtml);
			}
		}

		$(this).toggleClass('fold');
		$(this).toggleClass('unfold');
		$('#ticket_box').toggle('slow');
	});

	//初始化地域联动JS模板
	template.compile("areaTemplate",areaTemplate);

	//收货地址数据
	orderFormInstance.addressInit("{$this->defaultAddressId}");

	//配送方式初始化
	orderFormInstance.deliveryInit("{$this->custom['delivery']}");

	//自提点初始化
	$('[name="takeself"]').val({$this->custom['takeself']});

	//设置是否免运费
	orderFormInstance.freeFreight = {echo:$this->freeFreight ? 1 : 0};

	//支付方式
	orderFormInstance.paymentInit("{$this->custom['payment']}");

	//商品价格
	orderFormInstance.goodsSum = "{$this->final_sum}";
});

/**
 * 生成地域js联动下拉框
 * @param name
 * @param parent_id
 * @param select_id
 */
function createAreaSelect(name,parent_id,select_id)
{
	//生成地区
	$.getJSON("{url:/block/area_child}",{"aid":parent_id,"random":Math.random()},function(json)
	{
		$('[name="'+name+'"]').html(template.render('areaTemplate',{"select_id":select_id,"data":json}));
	});
}

//[address]保存到常用的收货地址
function address_save()
{
	if(orderFormInstance.addressCheck())
	{
		$.getJSON('{url:/simple/address_add}',$('form[name="order_form"]').serialize(),function(content){
			if(content.data)
			{
				var addressLiHtml = template.render('addressLiTemplate',{"item":content.data});
				$('.addr_list').prepend(addressLiHtml);
				$('input:radio[name="radio_address"]:first').trigger('click');
			}
			orderFormInstance.addressSave();
		});
	}
}

//[delivery]根据省份地区ajax获取配送方式
function get_delivery(province)
{
	$.getJSON("{url:/block/order_delivery}",{"province":province,"total_weight":"{$this->weight}","goodsSum":"{$this->sum}"},function(content){

		//清空数据
		$('#deliveryFormTrBox').empty();

		for(var index in content)
		{
			var deliveryTrHtml = template.render('deliveryTrTemplate',{item:content[index]});
			$('#deliveryFormTrBox').append(deliveryTrHtml);
		}

		if($.trim($('#deliveryFormTrBox').text()) == '')
		{
			alert('需要从后台添加配送方式才能下单');
			return;
		}

		//是否选中无法送达的配送方式
		if(orderFormInstance.deliveryActiveId)
		{
			var defaultDeliveryItem = $('input[type="radio"][name="delivery_id"][value="'+orderFormInstance.deliveryActiveId+'"]');
			if(defaultDeliveryItem.length > 0)
			{
				//不能送达省份时
				if(defaultDeliveryItem.attr('disabled'))
				{
					defaultDeliveryItem.attr('checked',false);

					tips('您选择的省份当前的配送方式不能送达！请重新选择配送方式');

					//切换视图方式
					if(orderFormInstance.deliveryMod == 'exit')
					{
						orderFormInstance.deliveryModToggle();
					}
					return;
				}

				defaultDeliveryItem.trigger('click');

				//默认配送方式
				if($('#paymentBox:hidden').length == 1 && orderFormInstance.paytype == 0)
				{
					orderFormInstance.deliverySave();
				}
			}
		}
	});
}

//添加代金券
function add_ticket()
{
	var ticket_num = $('#ticket_num').val();
	var ticket_pwd = $('#ticket_pwd').val();

	if(ticket_num == '' || ticket_pwd == '')
	{
		alert('请填写卡号和密码');
		return '';
	}

	$.getJSON('{url:/block/add_download_ticket}',{"ticket_num":ticket_num,"ticket_pwd":ticket_pwd},function(content){
		if(content.isError == false)
		{
			is_success = true;
			$('[name="ticket_id"]').each(
				function()
				{
					if($(this).val() == content.data.id)
					{
						alert('代金券已经存在，不要重复添加');
						is_success = false;
					}
				}
			);

			if(is_success)
			{
				var ticketHtml = template.render('ticketTrTemplate',{item:content.data});
				$('#ticket_show_box').append(ticketHtml);
				$('[name="ticket_id"]').attr('checked',true);
				$('[name="ticket_id"]:last').trigger('click');
			}
			$('#ticket_num').val('');
			$('#ticket_pwd').val('');
		}
		else
		{
			alert(content.message);
		}
	});
}

//取消红包
function cancel_ticket()
{
	$('#ticket_a').trigger('click');
	$('[name="ticket_id"]').attr('checked',false);
	orderFormInstance.doAccount();
}

//选择自提点
function selectTakeself(deliveryId)
{
	art.dialog.open("{url:/block/takeself}",{
		title:'选择自提点',
		okVal:'选择',
		ok:function(iframeWin, topWin)
		{
			var takeselfJson = $(iframeWin.document).find('[name="takeselfItem"]:checked').val();

			if(!takeselfJson)
			{
				alert('请选择自提点');
				return false;
			}
			var json = $.parseJSON(takeselfJson);
			$('#takeself'+deliveryId).empty();
			$('[name="takeself"]').val(json.id);
			$('#takeself'+deliveryId).html(template.render('takeselfTemplate',{"item":json}));
			return true;
		}
	});
}
</script>
<section class="member_main">
<div class="white_bg">
		<ul class="list-unstyled container">
			<li><i class="fa fa-shopping-cart kcart"></i>
</li>
			<li><a href="#">填写和提交订单信息</a></li>
		</ul>
	</div>
	<div class="height15"></div>


<div class="container info">

	<form action='{url:/simple/cart3}' method='post' name='order_form' callback='orderFormInstance.isSubmit();'>

		<input type='hidden' name='timeKey' value='{echo:time()}' />
		<input type='hidden' name='direct_gid' value='{$this->gid}' />
		<input type='hidden' name='direct_type' value='{$this->type}' />
		<input type='hidden' name='direct_num' value='{$this->num}' />
		<input type='hidden' name='direct_promo' value='{$this->promo}' />
		<input type='hidden' name='direct_active_id' value='{$this->active_id}' />
		<input type='hidden' name='takeself' value='0' />



<div class="cart_box m_10">


			<div class="cont">
		<!--地址管理 开始-->
		<div class="">
			<div class="info_head">
			
					<a class="normal f12" href="javascript:void(0)" id="addressToggleButton" onclick="orderFormInstance.addressModToggle();"><span>[退出]</span></a>
						收货人信息
			</div>



<!--地址展示 开始-->
	<div class="table info_table white" id="address_show_box" style='display:none'>
						

<ul id="addressShowBox"></ul>

<!--收货地址展示模板-->
<script type='text/html' id='addressShowTemplate'>
<li class="kli">
<div class="kleft left">收货人姓名：</div>
<div class="kright left"><%=accept_name%></div>


</li>
<li  class="kli">
<div class="kleft left ">省份：</div>
<div class="kright left khidden"><%=province_val%> <%=city_val%> <%=area_val%></div>
</li>
<li  class="kli">
<div class="kleft left">地址：</div>
<div class="kright left khidden"><%=address%></div>
</li>
<li  class="kli">
<div class="kleft left">手机号码：</div>
<div class="kright left"><%=mobile%></div>
</li>
<li  class="kli">
<div class="kleft left">固定电话：</div>
<div class="kright left"><%=teldivhone%></div>
</li>
<li  class="kli">
<div class="kleft left">邮政编码：</div>
<div class="kright left"><%=zip%></div>
</li>
</script>


</div>
					<!--地址展示 结束-->

		




			<!--收货表单信息 开始-->
			<div id='address_often' class="prompt_4 m_10">
				<ul class="addr_list block-row" style="padding-bottom:0">
					{foreach:items=$this->addressList}
					<li>
						<label><input class="radio" name="radio_address" type="radio" value="{$item['id']}" onclick='orderFormInstance.addressSelected({echo:JSON::encode($item)});' />{$item['accept_name']}&nbsp;&nbsp;&nbsp;&nbsp;{$item['province_val']} {$item['city_val']} {$item['area_val']} {$item['address']}</label>
					</li>
					{/foreach}
					<li>
						<label><input type='radio' name='radio_address' onclick='orderFormInstance.addressEmpty();' value='' />其他收货地址</label>
					</li>
				</ul>

				<!--收货地址项模板-->
				<script type='text/html' id='addressLiTemplate'>
				<li>
					<label><input class="radio" name="radio_address" type="radio" value="<%=item['id']%>" onclick='orderFormInstance.addressSelected(<%=jsonToString(item)%>);' /><%=item['accept_name']%>&nbsp;&nbsp;&nbsp;&nbsp;<%=item['province_val']%> <%=item['city_val']%> <%=item['area_val']%> <%=item['address']%></label>
				</li>
				</script>
			</div>

					<ul id='address_form' class="block-row">
					            <li><div class="col-md-12 col-xs-12 column">
					                <div class=" col-md-4 col-xs-4 column">
					                    收货人姓名：
					                </div>
					                <div class=" col-md-8 col-xs-8">
					                    <input type="text" class="form-control" name="accept_name" pattern='required' alt='收件人姓名不能为空' />
					                </div>
					            </div>
					        </li>
					        <li>
					            <div class="col-md-12 col-xs-12 column">
					                <div class=" col-md-4 col-xs-4 column">
					                    省份：
					                </div>
					                <div class=" col-md-8 col-xs-8">
					                <select name="province" class="col-md-12 col-xs-12 column" child="city,area" onchange="areaChangeCallback(this);"></select>
					            <select name="city" class="col-md-12 col-xs-12 column" child="area" parent="province" onchange="areaChangeCallback(this);"></select>
					        <select name="area" class="col-md-12 col-xs-12 column" parent="city" pattern="required" alt="请选择收货地区"></select>
					    </div>
					</div>
					</li>
					<li>
					<div class="col-md-12 col-xs-12 column">
					    <div class=" col-md-4 col-xs-4 column">
					        地址：
					    </div>
					    <div class=" col-md-8 col-xs-8">

					        <input name='address' type="text" class="form-control" alt='格式不正确' pattern='required' />

					    </div>
					</div>
					</li>
					<li><div class="col-md-12 col-xs-12 column">
					<div class=" col-md-4 col-xs-4 column">
					    手机号码：
					</div>
					<div class="col-md-8 col-xs-8">
					    <input name='mobile' class="form-control" type="text" pattern='mobi' alt='格式不正确' />
					</div>
					</div>
					</li>
					<li>
					<div class="col-md-12 col-xs-12 column">
					<div class="col-md-4 col-xs-4 column">
					    固定电话：
					</div>
					<div class="col-md-8 col-xs-8">
					    <input type="text" class="form-control" pattern='phone' name='telphone' empty alt='格式不正确' />
					</div>
					</div>
					</li>
					<li>
					<div class="col-md-12 col-xs-12 column">
					<div class=" col-md-4 col-xs-4 column">
					    邮政编码：
					</div>
					<div class="col-md-8 col-xs-8">
					    <input name='zip' empty class="form-control" type="text" pattern='zip' alt='格式不正确' />
					</div>
					</div>
					</li>
					</ul>
			<!--收货表单信息 结束-->

			<label id='address_save_button'>
				<input type="button" value="保存收货人地址" class="btn" onclick="address_save();" />
			</label>
		</div>
		<!--地址管理 结束-->
	</div>
		<!--配送方式 开始-->
		<div class="" id='deliveryBox' style='display:none;'>
			

			<div class="info_head">
			
					<a class="normal f12" href="javascript:void(0)" id='deliveryToggleButton' onclick="orderFormInstance.deliveryModToggle();">[关闭]</a>配送方式
			</div>


			<!--配送展示 开始-->
			<div id="delivery_show_box" style='display:none'>
				<ul class="" id="deliveryShowBox"></ul>

				<!--配送方式展示模板-->
				<script type='delivery' id='deliveryShowTemplate'>
				<li class="kli">
					<div class="kleft left">配送方式：</div>
					<div class="kright left"><%=name%></div>
				</li>
				<li class="kli">
					<div class="kleft left">运费：</div>
					<div class="kright left">￥<%=price%></div>
				</li>
				</script>
			</div>
			<!--配送展示 结束-->

			<!--配送修改 开始-->
			<div id='delivery_form'>
				<ul id="deliveryFormTrBox" style="padding-bottom:1px" class="block-row"></ul>
				<script type='text/html' id='deliveryTrTemplate'>
				<li>
					<input type="radio" name="delivery_id" paytype="<%=item['type']%>" alt="<%=item['price']%>" value="<%=item['id']%>" <%if(item['if_delivery'] == 1){%>disabled="disabled" title="无法送达"<%}%> onclick='orderFormInstance.deliverySelected(<%=jsonToString(item)%>);' /><%=item['name']%>
					<%=item['description']%> 运费：￥<%=item['price']%> &nbsp;&nbsp;
					<%if(item['protect_price'] > 0){%>
						<label><input type="checkbox" onclick="orderFormInstance.doAccount();" name="insured" value="<%=item['protect_price']%>" />保价：￥<%=item['protect_price']%></label>
					<%}%>
					<%if(item['type'] == 2){%>
						<a href="javascript:selectTakeself(<%=item['id']%>);"><span class="red">选择自提点</span></a>
						<span id="takeself<%=item['id']%>"></span>
					<%}%>
				</li>
				</script>

				<script type='text/html' id='takeselfTemplate'>
					<%=item['province_str']%> <%=item['city_str']%> <%=item['area_str']%> <%=item['address']%> <%=item['phone']%> <%=item['mobile']%>
				</script>

				<ul class="block-row" style="padding-bottom:0">
					<li>
						指定送货时间：
						<label><input type='radio' name='accept_time' checked="checked" value='任意' />任意</label>
						<label><input type='radio' name='accept_time' value='周一到周五' />周一到周五</label>
						<label><input type='radio' name='accept_time' value='周末' />周末</label>
					</li>
				</ul>
			</div>
			<!--配送修改 结束-->

			<label id="delivery_save_button" ><input type="button" class="btn" onclick="orderFormInstance.deliverySave();" value="保存配送方式" /></label>
		</div>
		<!--配送方式 结束-->

		<!--支付方式 开始-->
		<div class="" id='paymentBox' style='display:none;'>
			<div class="info_head">
						
						<a class="normal f12" href="javascript:void(0)" id='paymentToggleButton' onclick="orderFormInstance.paymentModToggle();">[关闭]</a>
						支付方式
					</div>

			<ul class="block-row" id='payment_form' style="padding-bottom:0">
				{set:$paymentList=Api::run('getPaymentList')}
				{foreach:items = $paymentList}
				{set:$paymentPrice = CountSum::getGoodsPaymentPrice($item['id'],$this->sum);}
				<li>
					<input class="radio" name="payment" alt="{$paymentPrice}" onclick='orderFormInstance.paymentSelected({echo:JSON::encode($item)});' title="{$item['name']}" type="radio" value="{$item['id']}" />{$item['name']}
					{$item['note']} 支付手续费：￥{$paymentPrice}
				</li>
				{/foreach}
			</ul>

			<div id="payment_show_box" style='display:none;'>
				<ul class="" id="paymentShowBox"></ul>

				<!--支付方式模板-->
				<script type='text/html' id='paymentShowTemplate'>
					<li class="kli">
						<div class="kleft left">支付方式：</div>
						<div class="kright left"><%=name%></div>
					</li>
				</script>
			</div>

			<label id='payment_save_button'><input type="button"  class="btn" onclick="orderFormInstance.paymentSave();" value="保存支付方式" /></label>
		</div>
		<!--支付方式 结束-->

		<!--订单留言 开始-->
		<div class="">
		<div class="info_head">
						
						<a class="normal f12" href="javascript:void(0)" id='messageToggleButton' onclick="orderFormInstance.messageModToggle();">[修改]</a>
						订单附言
					</div>

			<div id='message_show_box'>
				<ul >
					<li id="messageShowBox"></li>
				</ul>
			</div>

			<ul  id='message_form' style='display:none;'>
				<li>
					订单附言：
					<input class="form-control" type="text" name='message' />
				</li>
			</ul>

			<label id='message_save_button' style='display:none'><input type="button" class="btn" onclick="orderFormInstance.messageSave();" value="保存订单附言" /></label>
		</div>
		<!--订单留言 结束-->

		<!--购买清单 开始-->
		<div class="block-box">
			<div class="info_head">购买的商品</div >
			<ul class="block-row" {if:empty($this->promotion)}style="display:none"{/if}>
				{foreach:items = $this->promotion}
				<li class="indent blue">{$item['plan']}，{$item['info']}</li>
				{/foreach}
			</ul>

			<!-- 商品展示 开始-->
			{foreach:items = $this->goodsList}

<div class="pro_list border-bottom">
		<div class="col-xs-4">
			<a href="{url:/site/products/id/$item[goods_id]}"><img src="{url:/pic/thumb/img/$item[img]/w/80/h/80}" class="img-responsive" alt=""></a>
		</div>
		<div class="col-xs-5">
			<h10><a href="{url:/site/products/id/$item[goods_id]}">{$item['name']}</a></h10><br>
			{if:isset($item['spec_array'])}
			<h10 >{set:$spec_array=Block::show_spec($item['spec_array']);}
					{foreach:items=$spec_array item=$specValue key=$specName}
						{$specName}：{$specValue} &nbsp&nbsp
					{/foreach}
					</h10>
			{/if}

		</div>

		<div class="col-xs-3">
			<h10>数量：{$item['count']}</h10><br>
			<h10>小计：￥{$item['sum']}</h10>

		</div>
	</div>






			
			{/foreach}
			<!-- 商品展示 结束-->
		</div>
		<!--购买清单 结束-->

		<!--金额结算-->
		<div class="block-box" id='amountBox' style='display:none;'>
			<div class="info_head">结算信息</div>

				<ul class="list-group" style="background:#fff">
					<li>
						{if:$this->final_sum != $this->sum}优惠后总金额{else:}商品总金额{/if}：<strong>{$this->final_sum}</strong> - 代金券：<strong name='ticket_value'>0</strong> + 税金：<strong id='tax_fee'>0</strong> + 运费总计：<strong id='delivery_fee_show'>0</strong> + 保价：<strong id='protect_price_value'>0</strong> + 支付手续费：<strong id='payment_value'>0</strong>
					</li>
					<li>
						<input type="button"  class="btn" id="ticket_a" value="使用代金券" />
					</li>
					<li>
						<!--代金券列表 开始-->
						<div style='display:none' id='ticket_box'>
							<ul  id='ticket_show_box'></ul>

							<!--代金券模板-->
							<script type='text/html' id='ticketTrTemplate'>
							<li>
								<label><input class="radio" name="ticket_id" onclick="orderFormInstance.doAccount();" type="radio" value="<%=item.id%>" alt="<%=item.value%>" /><%=item.name%></label>
								编号：<%=item.card_name%>
								优惠：<span class="red2">￥<b><%=item.value%></b></span>
							</li>
							</script>

							<ul >
								<li><input type="button" class="btn" onclick="cancel_ticket();" value="取消代金券" /></li>
								<li>卡号：<input type='text' class="form-control" id='ticket_num' /></li>
								<li>密码：<input type='password' class="form-control" id='ticket_pwd' /></li>
								<li style="margin-top:20px"><input type="button" class="btn" onclick="add_ticket();" value="添加" /></li>
								<li>使用了代金券 可以优惠 <strong class="red2" name='ticket_value'>0</strong> 元</li>
							</ul>
						</div>
						<!--代金券列表 结束-->
					</li>
				</ul>
			</div>
				<ul  style="padding-bottom:0">
					<li>
						是否需要发票？(税金:￥{$this->goodsTax}) <input class="radio" onclick="orderFormInstance.doAccount();$('#tax_title').toggle();" name="taxes" type="checkbox" value="{$this->goodsTax}" />
					</li>
					<li>
						<label id="tax_title" style='display:none'>
							发票抬头：<input type='text' class="form-control" name='tax_title' />
						</label>
					</li>
					<li >
						应付总额：<span class="red">￥<strong id='final_sum'>{$this->final_sum}</strong></span>元
					</li>
					<li>
						<input type="submit" class="btn" style="width:100%" value="提交订单" />
					</li>
				</ul>
		</div>
	</form>
</div>
</section>